//
//  LGPatientDetailPlanCell.m
//  HeartDiseaseManage
//
//  Created by Bovin on 2023/9/8.
//  照护计划

#import "LGPatientDetailPlanCell.h"
#import "LGPatientDetailItemView.h"

@interface LGPatientDetailPlanCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *newestIcon;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;

@end

@implementation LGPatientDetailPlanCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSString *is_new = LGNSString(dataDic[@"is_new"]);
    self.newestIcon.hidden = ([is_new integerValue]>0)?NO:YES;
    CGFloat leftMargin = ([is_new integerValue]>0)?viewPix(62):viewPix(28);
    [self.dateLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(leftMargin);
    }];
    self.dateLabel.text = LGNSString(dataDic[@"date"]);
    self.nameLabel.text = LGNSString(dataDic[@"type_name"]);
    self.statusLabel.text = LGNSString(dataDic[@"status_name"]);
    // 1排队中 3未完成 4已完成
    NSString *stauts = LGNSString(dataDic[@"status"]);
    NSString *expired = LGNSString(dataDic[@"is_expired"]);
    NSString *statusColor = ([stauts isEqualToString:@"3"] && [expired isEqualToString:@"1"])?@"#EB5757":@"#4C87FD";
    NSString *dateColor = (([stauts isEqualToString:@"3"] && [expired isEqualToString:@"1"])||[stauts isEqualToString:@"1"])?@"#333333":@"#666666";
    self.dateLabel.textColor = [UIColor colorWithString:dateColor];
    self.statusLabel.textColor = [UIColor colorWithString:statusColor];
    NSString *type = LGNSString(dataDic[@"task_type"]);
    //二期手术、冠脉造影、再次入院 可点
    if([type isEqualToString:@"2"]||[type isEqualToString:@"3"]||[type isEqualToString:@"4"]){
        self.tipView.hidden = NO;
    }else{
        self.tipView.hidden = YES;
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.newestIcon];
    [self.contentView addSubview:self.dateLabel];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.statusLabel];
    [self.contentView addSubview:self.tipView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.equalTo(self.contentView).offset(-viewPix(16));
        make.left.bottom.equalTo(self.contentView).offset(viewPix(16));
    }];
    [self.newestIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.top.equalTo(self.contentView).offset(viewPix(8));
        make.bottom.equalTo(self.contentView).offset(-viewPix(2));
        make.width.equalTo(@(viewPix(30)));
        make.height.equalTo(@(viewPix(18)));
    }];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.centerY.equalTo(self.newestIcon);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dateLabel.mas_right).offset(viewPix(8));
        make.centerY.equalTo(self.newestIcon);
    }];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(8));
        make.centerY.equalTo(self.newestIcon);
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.centerY.equalTo(self.newestIcon);
        make.width.height.equalTo(@(viewPix(12)));
    }];
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:0];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIImageView *)newestIcon{
    if(!_newestIcon){
        _newestIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"患者档案-最新"]];
    }
    return _newestIcon;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _dateLabel;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"" colorString:@"#4C87FD" textFont:LGFont(12) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _statusLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip12"]];
    }
    return _tipView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
